package com.blockmeta.bbs.businesslibrary.net.pojo;

import android.text.TextUtils;

import com.blockmeta.bbs.baselibrary.utils.CalculateUtil;
import com.blockmeta.bbs.businesslibrary.widget.vote.IVoteOptionsList;
import com.blockmeta.bbs.businesslibrary.widget.vote.IVoteOptionsPOJO;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by author on 2018/3/27.
 */

public class BBSVoteAuthorPOJO implements IVoteOptionsPOJO<BBSVoteAuthorPOJO.PolloptionsBean> {

    /**
     * mPostName : 140449
     * title : 【投票】你觉得比特币的合理价格是多少？
     * post_date : 1521510347
     * desc : 我们知道比特币从去年中旬开始崛起，从1.6万RMB到年底的破12万RMB，然后18年初到目前的4-5万RMB，用过山车来形容币价一点都不为过！那么你觉得比特币最合理的价格应该是多 ...
     * content : 我们知道比特币从去年中旬开始崛起，从1.6万RMB到年底的破12万RMB，然后18年初到目前的4-5万RMB，用过山车来形容币价一点都不为过！<br/><br/>那么你觉得比特币最合理的价格应该是多少呢？你觉得18年比特币的价格会维持在什么水准呢？你们可以投票，也可以在下方评论留言表达观点！<br/>
     * author_info : {"mPostName":"236094","name":"陈震","desc":"","avatar":"http://8btc.com/uc_server/images/noavatar_middle.gif"}
     * category : {"name":"区块链论坛","threads":"12926","posts":"109977","mPostName":"61","link":"/forum-61-1.html"}
     * getViews : 2077
     * replies : 30
     * lastpost : 1522115110
     * lastposter : foolfool
     * attachments : []
     * polloptions : [{"polloptionid":"5862","polloption":"10万美刀+","votes":"56","width":"44.8%","percent":44.8,"optiontype":"radio"},{"polloptionid":"5863","polloption":"5~10万美刀","votes":"13","width":"10.4%","percent":10.4,"optiontype":"radio"},{"polloptionid":"5864","polloption":"1~5万美刀","votes":"29","width":"23.2%","percent":23.2,"optiontype":"radio"},{"polloptionid":"5865","polloption":"0.5~1万美刀","votes":"8","width":"6.4%","percent":6.4,"optiontype":"radio"},{"polloptionid":"5866","polloption":"0.1美刀","votes":"4","width":"3.2%","percent":3.2,"optiontype":"radio"},{"polloptionid":"5867","polloption":"白菜价","votes":"15","width":"12%","percent":12,"optiontype":"radio"}]
     * poll_expiration : 1524102347
     * poll_optiontype : radio
     * favid : 0
     */
    private static DecimalFormat mDecimalFormat = new DecimalFormat("0.#");
    private int id;
    private String title;
    private String post_date;
    private String desc;
    private String content;
    private AuthorInfoBean author_info;
    private CategoryBean category;
    private String views;
    private String replies;
    private String lastpost;
    private String lastposter;
    private long poll_expiration;
    private String poll_optiontype;
    private int favid;
    private List<?> attachments;
    private List<PolloptionsBean> polloptions;
    private int like;
    private String attitude;
    private  int pid;
    private int ispolled;

    public int getIspolled() {
        return ispolled;
    }

    public void setIspolled(int ispolled) {
        this.ispolled = ispolled;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getAttitude() {
        return attitude;
    }

    public void setAttitude(String attitude) {
        this.attitude = attitude;
    }

    public int getLike() {
        return like;
    }

    public void setLike(int like) {
        this.like = like;
    }

    public String getPoll_votercount() {
        return poll_votercount;
    }

    public void setPoll_votercount(String poll_votercount) {
        this.poll_votercount = poll_votercount;
    }

    private String poll_votercount;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPost_date() {
        return post_date;
    }

    public void setPost_date(String post_date) {
        this.post_date = post_date;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public AuthorInfoBean getAuthor_info() {
        return author_info;
    }

    public void setAuthor_info(AuthorInfoBean author_info) {
        this.author_info = author_info;
    }

    public CategoryBean getCategory() {
        return category;
    }

    public void setCategory(CategoryBean category) {
        this.category = category;
    }

    public String getViews() {
        return views;
    }

    public void setViews(String views) {
        this.views = views;
    }

    public String getReplies() {
        return replies;
    }

    public void setReplies(String replies) {
        this.replies = replies;
    }

    public String getLastpost() {
        return lastpost;
    }

    public void setLastpost(String lastpost) {
        this.lastpost = lastpost;
    }

    public String getLastposter() {
        return lastposter;
    }

    public void setLastposter(String lastposter) {
        this.lastposter = lastposter;
    }

    public long getPoll_expiration() {
        return poll_expiration;
    }


    public void setPoll_expiration(long poll_expiration) {
        this.poll_expiration = poll_expiration;
    }

    public boolean isVoteEnd (){
        return System.currentTimeMillis()/1000>poll_expiration;
    }
    public String getPoll_optiontype() {
        return poll_optiontype;
    }

    public void setPoll_optiontype(String poll_optiontype) {
        this.poll_optiontype = poll_optiontype;
    }

    public int getFavid() {
        return favid;
    }

    public void setFavid(int favid) {
        this.favid = favid;
    }

    public List<?> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<?> attachments) {
        this.attachments = attachments;
    }

    public List<PolloptionsBean> getPolloptions() {
        return polloptions;
    }

    public void setPolloptions(List<PolloptionsBean> polloptions) {
        this.polloptions = polloptions;
    }
    /** ----------------------- IVoteOptionsPOJO 接口实现的方法---------------------*/
    @Override
    public String getParticipantsCount() {
        return TextUtils.isEmpty(poll_votercount)?"0":poll_votercount;
    }

    @Override
    public List<PolloptionsBean> getOptionList() {
        return polloptions;
    }


    @Override
    public boolean isSingleChoice() {
        return "radio".equals(poll_optiontype);
    }

    @Override
    public boolean isParticipated() {
        return ispolled == 1;
    }
    /** ---------------------- 到此为止 ---------------------------------------------*/

    public static class AuthorInfoBean {
        /**
         * mPostName : 236094
         * name : 陈震
         * desc :
         * avatar : http://8btc.com/uc_server/images/noavatar_middle.gif
         */

        private String id;
        private String name;
        private String desc;
        private String avatar;
        private String grouptitle;
        private String date;

        public String getDate() {
            return date;
        }

        public void setDate(String date) {
            this.date = date;
        }

        public String getGrouptitle() {
            return grouptitle;
        }

        public void setGrouptitle(String grouptitle) {
            this.grouptitle = grouptitle;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }
    }

    public static class CategoryBean {
        /**
         * name : 区块链论坛
         * threads : 12926
         * posts : 109977
         * mPostName : 61
         * link : /forum-61-1.html
         */

        private String name;
        private String threads;
        private String posts;
        private String id;
        private String link;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getThreads() {
            return threads;
        }

        public void setThreads(String threads) {
            this.threads = threads;
        }

        public String getPosts() {
            return posts;
        }

        public void setPosts(String posts) {
            this.posts = posts;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }
    }

    public static class PolloptionsBean implements IVoteOptionsList{
        /**
         * polloptionid : 5862
         * polloption : 10万美刀+
         * votes : 56
         * width : 44.8%
         * percent : 44.8
         * optiontype : radio
         */

        private String polloptionid;
        private String polloption;
        private String votes;
        private String width;
        private double percent;
        private String optiontype;
        private int ispolled;
        private ImageInfo imginfo;

        public String getPolloptionid() {
            return polloptionid;
        }

        public void setPolloptionid(String polloptionid) {
            this.polloptionid = polloptionid;
        }

        public String getPolloption() {
            return polloption;
        }

        public void setPolloption(String polloption) {
            this.polloption = polloption;
        }

        public String getVotes() {
            return votes;
        }

        public void setVotes(String votes) {
            this.votes = votes;
        }

        public String getWidth() {
            return width;
        }

        public void setWidth(String width) {
            this.width = width;
        }

        public double getPercent() {
            return percent;
        }

        public void setPercent(double percent) {
            this.percent = percent;
        }

        public String getOptiontype() {
            return optiontype;
        }

        public void setOptiontype(String optiontype) {
            this.optiontype = optiontype;
        }

        public static class ImageInfo{
            public String small;
        }
        /** -------------------------- IVoteOptionsList 接口的实现 ------------------------*/
        @Override
        public String getVoteIcon() {
            return imginfo==null?"":imginfo.small;
        }

        @Override
        public String getVoteOption() {
            return polloption;
        }

        @Override
        public boolean isChoosed() {
            return ispolled==1;
        }

        @Override
        public void setChoosed(boolean choosed) {
            ispolled = choosed?1:0;
        }

        @Override
        public String getVoteCounts() {
            return TextUtils.isEmpty(votes)?"0票":votes+"票";
        }

        @Override
        public double getVotePercent() {
            return CalculateUtil.div(percent,100d,3);
        }

        @Override
        public String getVotePercentStr() {
            return mDecimalFormat.format(percent)+"%";
        }

        @Override
        public String getOptionID() {
            return polloptionid;
        }
        /** --------------------------------至此结束-----------------------------------------*/
    }
}
